#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <liblds/dllist.h>
int main()
{
	LDLList * L1;
	L1=Create_LDLList();
	int *a=(int *)malloc(sizeof(int));
// 插入测试 (尾插入)
	for(int i=1;i<=1000;++i){
		*a=i;
		Insert_LDLList(L1,i,a);
		a=(int *)malloc(sizeof(int));
		if(Length_LDLList(L1) != i){
			printf("Debug: 1 Insert at Tail\n");
			printf("ERROR: Insert Or Length\n");
			printf("i = %d\n",i);
			printf("Length = %d\n",Length_LDLList(L1));
			free(a);
			goto DESTROY;
		}
	}
	*a=0;
// Get测试
	for(int i=1;i<=1000; ++i){
		bool b= GetItem_LDLList(L1,i,(void *)&a);
		if(*a != i || b == false){
			printf("Debug: 2 GetItem\n");
			printf("ERROR: getitem\n");
			printf("i = %d\n",i);
			printf("a = %d\n",*a);
			goto DESTROY; // 销毁资源
		}
	}
	Clear_LDLList(L1,free);
	if(Length_LDLList(L1) != 0){
		printf("Debug: 3 Clear\n");
		printf("ERROR: Clear\n");
		goto DESTROY;
	}
// 插入测试 (头插入)
	a=(int *)malloc(sizeof(int));
	for(int i=1;i<=100; ++i){
		*a=i;
		a=(int *)malloc(sizeof(int));
		Insert_LDLList(L1,1,a);
		if(Length_LDLList(L1) != i){
			printf("Debug: 4 Insert at Head\n");
			printf("ERROR: Insert Or Length\n");
			printf("i = %d\n",i);
			printf("Length = %d\n",Length_LDLList(L1));
			free(a);
			goto DESTROY;
		}
	}
	free(NULL);
// 随机插入测试 （准备中）
DESTROY:
	printf("DESTROY\n");
	Destroy_LDLList(&L1,free);
	if(L1 != NULL)
		printf("error destroy!\n");
	return 0;
}
